package com.engine.salary.biz;

import com.engine.salary.entity.salarysob.po.SalarySobItemGroupPO;
import com.engine.salary.mapper.salarysob.SalarySobItemGroupMapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.session.SqlSession;
import weaver.conn.mybatis.MyBatisFactory;

import java.util.Collection;
import java.util.List;

public class SalarySobItemGroupBiz {

    public SalarySobItemGroupPO getById(Long id) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            return mapper.getById(id);
        } finally {
            sqlSession.close();
        }
    }

    public List<SalarySobItemGroupPO> listSome(SalarySobItemGroupPO build) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            return mapper.listSome(build);
        } finally {
            sqlSession.close();
        }
    }

    public void batchInsert(Collection<SalarySobItemGroupPO> salarySobItemGroupPOS) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            mapper.batchInsert(salarySobItemGroupPOS);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    public void insert(SalarySobItemGroupPO po) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            mapper.insertIgnoreNull(po);
        } finally {
            sqlSession.commit();
            sqlSession.close();
        }
    }

    public void deleteBySalarySobIds(Collection<Long> salarySobIds) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            mapper.deleteBySalarySobIds(salarySobIds);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }


    public void deleteByIds(List<Long> ids) {

        if (CollectionUtils.isEmpty(ids)) {
            return;
        }

        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            mapper.deleteByIds(ids);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    public void update(SalarySobItemGroupPO po) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobItemGroupMapper mapper = sqlSession.getMapper(SalarySobItemGroupMapper.class);
            mapper.updateIgnoreNull(po);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }
}
